using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Users Data Object Class
  /// </summary>
  public partial class DOUsers
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Users UserId
		/// </summary>
		public const string RowUserId = "User_ID";

		/// <summary>
		/// The Table Column for the Users UserLogon
		/// </summary>
		public const string RowUserLogon = "UserLogon";

		/// <summary>
		/// The Table Column for the Users UserPassword
		/// </summary>
		public const string RowUserPassword = "UserPassword";

		/// <summary>
		/// The Table Column for the Users FirstName
		/// </summary>
		public const string RowFirstName = "FirstName";

		/// <summary>
		/// The Table Column for the Users Surname
		/// </summary>
		public const string RowSurname = "Surname";

		/// <summary>
		/// The Table Column for the Users Extention
		/// </summary>
		public const string RowExtention = "Extention";

		/// <summary>
		/// The Table Column for the Users Telephone
		/// </summary>
		public const string RowTelephone = "Telephone";

		/// <summary>
		/// The Table Column for the Users Cellphone
		/// </summary>
		public const string RowCellphone = "Cellphone";

		/// <summary>
		/// The Table Column for the Users Email
		/// </summary>
		public const string RowEmail = "Email";

		/// <summary>
		/// The Table Column for the Users DivisionName
		/// </summary>
		public const string RowDivisionName = "DivisionName";

		/// <summary>
		/// The Table Column for the Users DepartmentName
		/// </summary>
		public const string RowDepartmentName = "DepartmentName";

		/// <summary>
		/// The Table Column for the Users Access
		/// </summary>
		public const string RowAccess = "Access";

		/// <summary>
		/// The Table Column for the Users Active
		/// </summary>
		public const string RowActive = "Active";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spUsers_Create";
private const string m_StoredProcedureConstDelete = "spUsers_Delete";
private const string m_StoredProcedureConstRetrieve = "spUsers_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spUsers_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spUsers_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private long m_UserId;
		private string m_UserLogon;
		private string m_UserPassword;
		private string m_FirstName;
		private string m_Surname;
		private string m_Extention;
		private string m_Telephone;
		private string m_Cellphone;
		private string m_Email;
		private string m_DivisionName;
		private string m_DepartmentName;
		private string m_Access;
		private bool m_Active;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOUsers> m_Userss = new List<DOUsers>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOUsers() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// UserId
		/// </summary>
		/// <remarks>
		/// This property contains the Users UserId
		/// </remarks>
		public long UserId
		{
			get { return (this.m_UserId); }
			set { this.m_UserId = value; }
		}

		/// <summary>
		/// UserLogon
		/// </summary>
		/// <remarks>
		/// This property contains the Users UserLogon
		/// </remarks>
		public string UserLogon
		{
			get { return (this.m_UserLogon); }
			set { this.m_UserLogon = value; }
		}

		/// <summary>
		/// UserPassword
		/// </summary>
		/// <remarks>
		/// This property contains the Users UserPassword
		/// </remarks>
		public string UserPassword
		{
			get { return (this.m_UserPassword); }
			set { this.m_UserPassword = value; }
		}

		/// <summary>
		/// FirstName
		/// </summary>
		/// <remarks>
		/// This property contains the Users FirstName
		/// </remarks>
		public string FirstName
		{
			get { return (this.m_FirstName); }
			set { this.m_FirstName = value; }
		}

		/// <summary>
		/// Surname
		/// </summary>
		/// <remarks>
		/// This property contains the Users Surname
		/// </remarks>
		public string Surname
		{
			get { return (this.m_Surname); }
			set { this.m_Surname = value; }
		}

		/// <summary>
		/// Extention
		/// </summary>
		/// <remarks>
		/// This property contains the Users Extention
		/// </remarks>
		public string Extention
		{
			get { return (this.m_Extention); }
			set { this.m_Extention = value; }
		}

		/// <summary>
		/// Telephone
		/// </summary>
		/// <remarks>
		/// This property contains the Users Telephone
		/// </remarks>
		public string Telephone
		{
			get { return (this.m_Telephone); }
			set { this.m_Telephone = value; }
		}

		/// <summary>
		/// Cellphone
		/// </summary>
		/// <remarks>
		/// This property contains the Users Cellphone
		/// </remarks>
		public string Cellphone
		{
			get { return (this.m_Cellphone); }
			set { this.m_Cellphone = value; }
		}

		/// <summary>
		/// Email
		/// </summary>
		/// <remarks>
		/// This property contains the Users Email
		/// </remarks>
		public string Email
		{
			get { return (this.m_Email); }
			set { this.m_Email = value; }
		}

		/// <summary>
		/// DivisionName
		/// </summary>
		/// <remarks>
		/// This property contains the Users DivisionName
		/// </remarks>
		public string DivisionName
		{
			get { return (this.m_DivisionName); }
			set { this.m_DivisionName = value; }
		}

		/// <summary>
		/// DepartmentName
		/// </summary>
		/// <remarks>
		/// This property contains the Users DepartmentName
		/// </remarks>
		public string DepartmentName
		{
			get { return (this.m_DepartmentName); }
			set { this.m_DepartmentName = value; }
		}

		/// <summary>
		/// Access
		/// </summary>
		/// <remarks>
		/// This property contains the Users Access
		/// </remarks>
		public string Access
		{
			get { return (this.m_Access); }
			set { this.m_Access = value; }
		}

		/// <summary>
		/// Active
		/// </summary>
		/// <remarks>
		/// This property contains the Users Active
		/// </remarks>
		public bool Active
		{
			get { return (this.m_Active); }
			set { this.m_Active = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOUsers> Userss
	{
	  get { return m_Userss; }
	  set { m_Userss = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowUser_ID + "=" + this.User_ID);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowUserId].ToString() != "")
			this.UserId = long.Parse(dr[RowUserId].ToString());

		if (dr[RowUserLogon].ToString() != "")
			this.UserLogon = dr[RowUserLogon].ToString();

		if (dr[RowUserPassword].ToString() != "")
			this.UserPassword = dr[RowUserPassword].ToString();

		if (dr[RowFirstName].ToString() != "")
			this.FirstName = dr[RowFirstName].ToString();

		if (dr[RowSurname].ToString() != "")
			this.Surname = dr[RowSurname].ToString();

		if (dr[RowExtention].ToString() != "")
			this.Extention = dr[RowExtention].ToString();

		if (dr[RowTelephone].ToString() != "")
			this.Telephone = dr[RowTelephone].ToString();

		if (dr[RowCellphone].ToString() != "")
			this.Cellphone = dr[RowCellphone].ToString();

		if (dr[RowEmail].ToString() != "")
			this.Email = dr[RowEmail].ToString();

		if (dr[RowDivisionName].ToString() != "")
			this.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			this.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowAccess].ToString() != "")
			this.Access = dr[RowAccess].ToString();

		if (dr[RowActive].ToString() != "")
			this.Active = bool.Parse(dr[RowActive].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOUsers Users = new DOUsers();
			
					if (dr[RowUserId].ToString() != "")
			Users.UserId = long.Parse(dr[RowUserId].ToString());

		if (dr[RowUserLogon].ToString() != "")
			Users.UserLogon = dr[RowUserLogon].ToString();

		if (dr[RowUserPassword].ToString() != "")
			Users.UserPassword = dr[RowUserPassword].ToString();

		if (dr[RowFirstName].ToString() != "")
			Users.FirstName = dr[RowFirstName].ToString();

		if (dr[RowSurname].ToString() != "")
			Users.Surname = dr[RowSurname].ToString();

		if (dr[RowExtention].ToString() != "")
			Users.Extention = dr[RowExtention].ToString();

		if (dr[RowTelephone].ToString() != "")
			Users.Telephone = dr[RowTelephone].ToString();

		if (dr[RowCellphone].ToString() != "")
			Users.Cellphone = dr[RowCellphone].ToString();

		if (dr[RowEmail].ToString() != "")
			Users.Email = dr[RowEmail].ToString();

		if (dr[RowDivisionName].ToString() != "")
			Users.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			Users.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowAccess].ToString() != "")
			Users.Access = dr[RowAccess].ToString();

		if (dr[RowActive].ToString() != "")
			Users.Active = bool.Parse(dr[RowActive].ToString());

            this.Userss.Add(Users);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
